package com.ruoyi.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.domain.Comment;
import com.ruoyi.domain.CommentDTO;
import com.ruoyi.mapper.CommentMapper;
import com.ruoyi.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评论表(Comment)表控制层
 */
@RestController
@RequestMapping("/comment")
public class CommentController extends BaseController {
    @Autowired
    private CommentService commentService;
    /**
     * 添加评论
     */
    @PostMapping("/addComment")
    public AjaxResult addComment(@RequestBody Comment comment){
        return AjaxResult.success(commentService.addComment(comment));
    }
    /**
     * 获取评论列表
     */
    @PostMapping("/getCommentList")
    public AjaxResult getCommentList(@RequestParam("title") String title){
        List<CommentDTO> commentList = commentService.getCommentList(title);
        return AjaxResult.success(commentList);
    }
    /**
     * 删除评论（只有当前userId==返回的userId才会显示）
     */
    @PostMapping("/deleteComment")
    public AjaxResult deleteComment(@RequestParam("CommentID") Long CommentID ){
        return AjaxResult.success(commentService.deleteComment(CommentID));
    }
    /**
     * 查询出用户的头像
     */
    @PostMapping("/getUserAvatar")
    public AjaxResult getUserAvatar(@RequestParam("userId") Long userId){
        return AjaxResult.success(commentService.getUserAvatar(userId));
    }
}
